// 文件路径: yt-user/yt-user-server/src/main/java/com/yt/user/config/WebMvcConfig.java
package com.yt.user.config;

import com.yt.user.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有/api/**请求，排除登录接口
        registry.addInterceptor(tokenInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/loginInfo/login")
                .excludePathPatterns("/api/loginInfo/logout");
    }
}